﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Eventing.Reader;

namespace org.swinchester.windowsevents.core
{
    public class EventSubscriber : EventReaderBase
    {
        public void Register()
        {
            EventLogWatcher watcher = null;
            try
            {
                EventLogQuery subscriptionQuery = new EventLogQuery(
                    SubscriptionConfig.EventLogName, SubscriptionConfig.EventPathType, SubscriptionConfig.EventLogQuery);

                watcher = new EventLogWatcher(subscriptionQuery);

                watcher.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(this.EventLogEventRead);

                // Begin subscribing to events the events
                watcher.Enabled = true;

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                watcher.Dispose();
            }
        }

        
    }
}
